<?php

namespace app\controller\api\v1\recruit;

use app\Request;
use app\model\v1\recruit\RecruitIndustry as IndustryModel;
use app\services\product\category\StoreProductCategoryServices;
use app\validate\api\recruit\createValidate;


/**
 * 求职招聘
 * Class RecruitCollection
 * @package app\controller\api\recruit
 */
class RecruitIndustry
{
    protected $services;
    protected $model;
    protected $userinfo = [];

    public function __construct(StoreProductCategoryServices $services)
    {
        $this->services = $services;
        $this->model = new IndustryModel();
    }


    /**
     * 求职招聘 - 获取行业数据列表
     * @return \think\Response
     */
    public function industry_list()
    {
        $industries = $this->getTree();
        return app('json')->success($industries);
    }

    public function getTree($pid=0)
    {
        $result = [];
        $data = $this->model->where('pid',$pid)->select()->toArray();
        if ($data){
            foreach($data as $k=> $val) {
                $result[$k] = $val;
                $list = $this->getTree($val['id']);
                if ($list){
                    foreach($list as $v2) {
                        $result[$k]['data'][] = $v2;
                    }
                }
            }
        }
        return $result;
    }
}